import numpy as np
import julia as JU
import pandas as pd
import plotly.graph_objects as go
import plotly.express as px
import plotly.io as pio
from sys import argv as argv


## 迭代次数
n = 1000
## 矩形区域端点
center = 0+0j
radius = 1.5+1.5j
const = eval(argv[1])
zoom = 1

## 调色函数
def f(x):
    if x<=100:
        return x**0.5
    else:
        return 100+(x-100)**0.5

## 输出矩阵区域内的Julia集
def Julia():
    global center,radius,n,const
    z = center+radius
    w = center-radius
    return JU.generate_Julia_in_dec(const,z,w,n,f)

## 显示Julia集
def show_Julia(ans):
    fig = px.imshow(ans[0], origin="lower", x=ans[1], y=ans[2]) #设置非矩阵显示模式, 并自定义坐标轴
    fig.update_layout(
        title = dict(
            text = "Julia Set, N = "+str(n)+", zoom = "+str(100*zoom)+"%",
        )
    )
    ## 输出png,需要下载包 kaleido (可运行pip install -U kaleido)
    pio.write_image(fig,"c_"+str(const)+"_"+str(zoom)+".png")

## 从原点处进行十次缩放
for i in range(0,eval(argv[2])):
    ans = Julia()
    print("zoom: "+str(100*zoom)+"%")
    show_Julia(ans)
    del ans
    zoom*=2
    radius/=2

